<template>
    <div class="hello">
        <h1>{{ msg }}</h1>
        <p>--------------------------------------我是华丽丽的分割线--------------------------------------</p>
        <p>$store.state.count : {{$store.state.count}}</p>
        <p>计算属性computedCount()：computedCount</p>
        <p>辅助函数 mapState：{{count}}</p>
        <p>
            <button @click="$store.commit('add')">+</button>&nbsp;
            <button @click="$store.commit('reduce')">-</button>

            <button @click="add(2)">+2</button>&nbsp;
            <button @click="reduce(2)">-2</button>
        </p>
    </div>
</template>

<script>
    import {
        mapState, mapMutations
    } from 'vuex'
    import store from '@/store/index'
    export default {
        name: 'hello',
        store,
        // computed: {
        //     computedCount() { // 方式一
        //         return store.state.count
        //     }
        // },
        computed: mapState(['count']), // 方式二

        data() {
            return {
                msg: 'Welcome to Your Vue.js App'
            }
        },
        methods: mapMutations(['add', 'reduce'])
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
    h1,
    h2 {
        font-weight: normal;
    }
    ul {
        list-style-type: none;
        padding: 0;
    }
    li {
        display: inline-block;
        margin: 0 10px;
    }
    a {
        color: #42b983;
    }
</style>
